package com.matrix.dungeon;

public class Array {
	int numOfItem = 0;
	int[] items;
	
	public Array(int pSize){
		items = new int[pSize];
	}
	
	public void add(int pItem){
		if(numOfItem >= items.length){
			throw new RuntimeException("Out of array boundary\n");
		}
		
		items[numOfItem] = pItem;
		numOfItem++;
	}
	
	public void del(int pItem){
		for(int i = 0;i < numOfItem;i++){
			if(items[i] == pItem){
				items[i] = items[numOfItem - 1];
				items[numOfItem - 1] = 0;
				numOfItem--;
				return;
			}
		}
		throw new RuntimeException("Array " + items + " has no item " + pItem + "\n");
	}
	
	public int isContain(int pItem){
		for(int i = 0;i < numOfItem;i++){
			if(items[i] == pItem){
				return i;
			}
		}
		return -1;
	}
}
